From a25f2798ee96c364e89903e247b935e31bb14188 Mon Sep 17 00:00:00 2001 From: "mwilli2@equilibrium.research.intel-research.net" Date: Tue, 24 Feb 2004 16:34:00 +0000 Subject: [PATCH] bitkeeper revision 1.747 (403b7cf86JDQU8_ljAm9SqJGvsVF4w) Physical hardware info dom0 op. --- .rootkeys | 1 + tools/examples/xc_physinfo.py | 20 +++++++++++++++ tools/xc/lib/xc.h | 10 ++++++++ tools/xc/lib/xc_misc.c | 22 +++++++++++++++++ tools/xc/py/Xc.c | 35 +++++++++++++++++++++++++++ xen/common/dom0_ops.c | 25 ++++++++++++++++++- xen/include/hypervisor-ifs/dom0_ops.h | 17 +++++++++++-- 7 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 tools/examples/xc_physinfo.py diff --git a/.rootkeys b/.rootkeys index cd0b234a42..788428d145 100644 --- a/.rootkeys +++ b/.rootkeys @@ -48,6 +48,7 @@ 40278d91ZjLhxdjjrGe8HEdwHLj5xQ tools/examples/netbsd 401d7e16NpnVrFSsR7lKKKfTwCYvWA tools/examples/xc_dom_control.py 401d7e16RJj-lbtsVEjua6HYAIiKiA tools/examples/xc_dom_create.py +403b7cf7J7FsSSoEPGhx6gXR4pIdZg tools/examples/xc_physinfo.py 401d7e16X4iojyKopo_j63AyzYZd2A tools/examples/xc_vd_tool.py 40278d94cIUWl2eRgnwZtr4hTyWT1Q tools/examples/xendomains 3f776bd2Xd-dUcPKlPN2vG89VGtfvQ tools/misc/Makefile diff --git a/tools/examples/xc_physinfo.py b/tools/examples/xc_physinfo.py new file mode 100644 index 0000000000..0d9db796c5 --- /dev/null +++ b/tools/examples/xc_physinfo.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +# Get information about the physical host machine + +import Xc + +xc = Xc.new() + +info = xc.physinfo() + +fmt_info = [ ( 'CPU cores', info['cores']), + ('Hyperthreads per core', info['ht_per_core']), + ('CPU Speed (MHz)', info['cpu_khz'] / 1000), + ('Total physical mem (MB)', info['total_pages'] / 256), + ('Free physical mem (MB)', info['free_pages'] / 256) ] + + +for (item, val) in fmt_info: + print "%-23s" % item, ':', val + diff --git a/tools/xc/lib/xc.h b/tools/xc/lib/xc.h index 5959c6265a..74a4fca2ed 100644 --- a/tools/xc/lib/xc.h +++ b/tools/xc/lib/xc.h @@ -118,6 +118,14 @@ typedef struct { u64 nr_sectors; } xc_vbdextent_t; +typedef struct { + int ht_per_core; + int cores; + unsigned long total_pages; + unsigned long free_pages; + unsigned long cpu_khz; +} xc_physinfo_t; + int xc_vbd_create(int xc_handle, u64 domid, unsigned short vbdid, @@ -153,5 +161,7 @@ int xc_readconsolering(int xc_handle, unsigned int max_chars, int clear); +int xc_physinfo(int xc_handle, + xc_physinfo_t *info); #endif /* __XC_H__ */ diff --git a/tools/xc/lib/xc_misc.c b/tools/xc/lib/xc_misc.c index e4efec4a41..63c53146b7 100644 --- a/tools/xc/lib/xc_misc.c +++ b/tools/xc/lib/xc_misc.c @@ -46,3 +46,25 @@ int xc_readconsolering(int xc_handle, return ret; } + +int xc_physinfo(int xc_handle, + xc_physinfo_t *put_info) +{ + int ret; + dom0_op_t op; + dom0_physinfo_t *got_info = &op.u.physinfo; + + op.cmd = DOM0_PHYSINFO; + op.interface_version = DOM0_INTERFACE_VERSION; + + if((ret = do_dom0_op(xc_handle, &op))) return ret; + + put_info->ht_per_core = got_info->ht_per_core; + put_info->cores = got_info->cores; + put_info->total_pages = got_info->total_pages; + put_info->free_pages = got_info->free_pages; + put_info->cpu_khz = got_info->cpu_khz; + + return 0; +} + diff --git a/tools/xc/py/Xc.c b/tools/xc/py/Xc.c index e34764b23f..2376be5eae 100644 --- a/tools/xc/py/Xc.c +++ b/tools/xc/py/Xc.c @@ -788,6 +788,34 @@ static PyObject *pyxc_readconsolering(PyObject *self, return PyString_FromStringAndSize(str, (ret < 0) ? 0 : ret); } +static PyObject *pyxc_physinfo(PyObject *self, + PyObject *args, + PyObject *kwds) +{ + XcObject *xc = (XcObject *)self; + PyObject *ret_obj; + int xc_ret; + xc_physinfo_t info; + + xc_ret = xc_physinfo(xc->xc_handle, &info); + + if(!xc_ret) + { + ret_obj = Py_BuildValue("{s:i,s:i,s:l,s:l,s:l}", + "ht_per_core", info.ht_per_core, + "cores", info.cores, + "total_pages", info.total_pages, + "free_pages", info.free_pages, + "cpu_khz", info.cpu_khz); + } + else + { + ret_obj = Py_BuildValue(""); /* None */ + } + + return ret_obj; +} + static PyMethodDef pyxc_methods[] = { { "domain_create", (PyCFunction)pyxc_domain_create, @@ -1010,6 +1038,13 @@ static PyMethodDef pyxc_methods[] = { " clear [int, 0]: Bool - clear the ring after reading from it?\n\n" "Returns: [str] string is empty on failure.\n" }, + { "physinfo", + (PyCFunction)pyxc_physinfo, + METH_VARARGS, "\n" + "Get information about the physical host machine\n" + "Returns [dict]: information about the hardware" + " [None]: on failure.\n" }, + { NULL, NULL, 0, NULL } }; diff --git a/xen/common/dom0_ops.c b/xen/common/dom0_ops.c index c225dffd3f..ab81ca662c 100644 --- a/xen/common/dom0_ops.c +++ b/xen/common/dom0_ops.c @@ -451,8 +451,31 @@ long do_dom0_op(dom0_op_t *u_dom0_op) op->u.readconsole.count, op->u.readconsole.cmd); } - break; + break; + + case DOM0_PHYSINFO: + { + extern int phys_proc_id[]; + extern unsigned long cpu_khz; + + dom0_physinfo_t *pi = &op->u.physinfo; + + int old_id = phys_proc_id[0]; + int ht = 0; + + while( ( ht < smp_num_cpus ) && ( phys_proc_id[ht] == old_id ) ) ht++; + pi->ht_per_core = ht; + pi->cores = smp_num_cpus / pi->ht_per_core; + pi->total_pages = max_page; + pi->free_pages = free_pfns; + pi->cpu_khz = cpu_khz; + + copy_to_user(u_dom0_op, op, sizeof(*op)); + ret = 0; + } + break; + default: ret = -ENOSYS; diff --git a/xen/include/hypervisor-ifs/dom0_ops.h b/xen/include/hypervisor-ifs/dom0_ops.h index f21c20fbcf..5e0abe6295 100644 --- a/xen/include/hypervisor-ifs/dom0_ops.h +++ b/xen/include/hypervisor-ifs/dom0_ops.h @@ -17,8 +17,7 @@ * This makes sure that old versions of dom0 tools will stop working in a * well-defined way (rather than crashing the machine, for instance). */ -#define DOM0_INTERFACE_VERSION 0xAAAA0006 - +#define DOM0_INTERFACE_VERSION 0xAAAA0007 /* * The following is all CPU context. Note that the i387_ctxt block is filled @@ -218,6 +217,19 @@ typedef struct dom0_gettbufs_st unsigned long phys_addr; } dom0_gettbufs_t; +/* + * Get physical information about the host machine + */ +#define DOM0_PHYSINFO 22 +typedef struct dom0_physinfo_st +{ + int ht_per_core; + int cores; + unsigned long cpu_khz; + unsigned long total_pages; + unsigned long free_pages; +} dom0_physinfo_t; + typedef struct dom0_op_st { unsigned long cmd; @@ -241,6 +253,7 @@ typedef struct dom0_op_st dom0_readconsole_t readconsole; dom0_pincpudomain_t pincpudomain; dom0_gettbufs_t gettbufs; + dom0_physinfo_t physinfo; } u; } dom0_op_t; -- 2.30.2